package org.shiro.service.impl;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.eis.SessionDAO;
import org.shiro.basic.entity.SystemUser;
import org.shiro.mapper.SystemUserMapper;
import org.shiro.service.ResourceService;
import org.shiro.utils.ShiroUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;

/**
 * 系统资源相关接口实现类
 *
 * @author LiKun
 * @date 2021/11/3 23:08
 */
@Service("resourceService")
public class ResourceServiceImpl implements ResourceService, Serializable {
    @Resource
    private SessionDAO sessionDAO;
    @Resource
    private ObjectMapper objectMapper;
    @Resource
    private SystemUserMapper systemUserMapper;

    @Override
    public SystemUser getUserInfo(String userId) throws JsonProcessingException {
        Session session = SecurityUtils.getSubject().getSession();
        System.out.println(objectMapper.writeValueAsString(session));
        return systemUserMapper.selectById(StrUtil.isEmpty(userId) ? userId : ShiroUtil.getUserId());
    }
}
